package org.iweb.html.impl.js.engine;

import org.iweb.html.api.AbstractHtmlElement;
import org.iweb.html.impl.basic.Div;
import org.iweb.html.impl.js.State;

public class JQueryEngine extends JavascriptEngine {

	@Override
	public JavascriptEngine addClass(AbstractHtmlElement element,
			String className) {
		getHtmlState().addState(element.getId(), new State("addclass", className));
		return this;
	}

	@Override
	public JavascriptEngine removeClass(AbstractHtmlElement element,
			String className) {
		getHtmlState().addState(element.getId(), new State("rmclass", className));
		return this;
	}

	@Override
	public JavascriptEngine open(AbstractHtmlElement element) {
		getHtmlState().addState(element.getId(), new State("open"));
		return this;
	}

	@Override
	public JavascriptEngine close(AbstractHtmlElement element) {
		getHtmlState().addState(element.getId(), new State("close"));
		return this;
	}

	@Override
	public JavascriptEngine show(AbstractHtmlElement element) {
		getHtmlState().addState(element.getId(), new State("show"));
		return this;
	}

	@Override
	public JavascriptEngine hide(AbstractHtmlElement element) {
		getHtmlState().addState(element.getId(), new State("hide"));
		return this;
	}

	@Override
	public JavascriptEngine text(AbstractHtmlElement element, String text) {
		addClass(element, "jq-message");
		removeClass(element, "jq-error");
		getHtmlState().addState(element.getId(), new State("text",text));
		return this;
	}

	@Override
	public JavascriptEngine textError(AbstractHtmlElement element, String text) {
		addClass(element, "jq-error");
		removeClass(element, "jq-message");
		getHtmlState().addState(element.getId(), new State("text",text));
		return this;
	}

	@Override
	public JavascriptEngine replace(AbstractHtmlElement el1,
			AbstractHtmlElement el2) {
		getHtmlState().addState(el1.getId(), new State("replace",el2.render()));
		return this;
	}

	@Override
	public JavascriptEngine append(AbstractHtmlElement el1,
			AbstractHtmlElement el2) {
		getHtmlState().addState(el1.getId(), new State("append",el2.render()));
		return this;
	}

	@Override
	public JavascriptEngine html(AbstractHtmlElement el1,
			AbstractHtmlElement el2) {
		getHtmlState().addState(el1.getId(), new State("html",el2.render()));
		return this;
	}

	@Override
	public JavascriptEngine removeClick(AbstractHtmlElement el1) {
		getHtmlState().addState(el1.getId(), new State("removeclick",el1.getId()));
		return this;
	}

	@Override
	public void redirect(String routePath) {
		//getHtmlState().addState("window", new State("redirect",AppManager.getAppState().getRequest().getContextPath()+routePath));
	}

	@Override
	public JavascriptEngine addClassBySelector(String selector, String className) {
		getHtmlState().addState(selector, new State("addclassBySelector", className));
		return this;
	}

	@Override
	public JavascriptEngine removeClassBySelector(String selector,
			String className) {
		getHtmlState().addState(selector, new State("rmclassBySelector", className));
		return this;
	}

	@Override
	public JavascriptEngine append(String el, AbstractHtmlElement el2) {
		getHtmlState().addState(el, new State("append",el2.render()));
		return this;
	}

	@Override
	public JavascriptEngine showTemp(AbstractHtmlElement element, long millisec) {
		getHtmlState().addState(element.getId(), new State("showTemp",""+millisec));
		return this;
	}

	@Override
	public void openUpload(Div iframecontent) {
		getHtmlState().addState(iframecontent.getId(), new State("openUpload",""));
	}

	@Override
	public void uploadProgress(long bytesRead, long contentLength) {
		getHtmlState().addState("progress", new State("read",Long.toString(bytesRead)));
		getHtmlState().addState("progress", new State("content",Long.toString(contentLength)));
	}

	@Override
	public JavascriptEngine textEditor(String text) {
		getHtmlState().addState("window", new State("textEditor",text));
		return this;
	}
}
